import { http } from "@/utils/http";
import type { Ingress, IngressList } from "./types";
import type { BaseResponse, PromiseRes } from "@/api/response";
import { k8sPathMergeReqs, type MakePathReq, type MergePathReq } from "./index";

export class K8sIngress {
  baseReq: MakePathReq = {
    src: "ingresses",
    app: "networking.k8s.io/v1"
  };

  getIngress = (req: MergePathReq): BaseResponse<IngressList> => {
    const api = k8sPathMergeReqs(req, this.baseReq);

    return http.get(api, { params: req.query });
  };

  getIngressDetail = (
    req: MergePathReq,
    data?: Ingress
  ): PromiseRes<Ingress> => {
    const api = k8sPathMergeReqs(req, this.baseReq, data);

    return http.get(api, { params: req.query });
  };

  updateIngress = (query?: MergePathReq, data?: Ingress): PromiseRes => {
    const api = k8sPathMergeReqs(query, this.baseReq, data);
    return http.put(api, { data });
  };

  deleteIngress = (req: MergePathReq, data?: Ingress): PromiseRes => {
    const api = k8sPathMergeReqs(req, this.baseReq, data);
    return http.delete(api, { data });
  };

  createIngress = (req: MergePathReq, data: Ingress): PromiseRes => {
    const api = k8sPathMergeReqs(req, this.baseReq, data);
    return http.post(api, { data });
  };
}
